package com.tao.controller.webpageController;

import com.tao.pojo.dto.OrderCancelDto;
import com.tao.pojo.dto.OrderPayDto;
import com.tao.pojo.dto.OrderSubmitDTO;
import com.tao.pojo.dto.PageSelectHistoryDto;
import com.tao.result.Result;
import com.tao.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController("webPageOrderController")//防止与app端重名
@Slf4j
@RequestMapping("/webPage/order")
public class OrderControllerUser {
    @Autowired
    OrderService orderService;

    @PostMapping("/submit")
    public Result orderSubmit(@RequestBody OrderSubmitDTO orderSubmitDTO){
        return Result.success( orderService.orderSubmit(orderSubmitDTO));
    }

    @PutMapping("/cancel")
   public Result orderCancel(@RequestBody OrderCancelDto orderCancelDto){
            orderService.orderCancel(orderCancelDto);
            return Result.success();
    }

    @GetMapping("/history")
    public Result getHistoryOrder(PageSelectHistoryDto pageSelectHistoryDto){
        return Result.success(orderService.getHistoryOrder(pageSelectHistoryDto));
    }

    @GetMapping("/orderDetail/{id}")
    public Result getOrderDetail(@PathVariable Integer id){
        return Result.success(orderService.getOrderDetail(id));
    }

    @PostMapping("/repetition/{id}")
    public Result repetitionOrder(@PathVariable Integer id){
        orderService.repetitionOrder(id);
        return Result.success();
    }

    @PostMapping("/pay")
    public Result payOrder(@RequestBody OrderPayDto orderPayDto){
        orderService.orderPay(orderPayDto);
        return Result.success();
    }
}
